package com.pvdnc.riru.system_server;

import android.annotation.SuppressLint;
import android.util.Log;

import com.pvdnc.riru.BitUtils;

import java.util.concurrent.atomic.AtomicReference;

@SuppressLint("PrivateApi")
public class AMSUtils {
    private static final String TAG=AMSUtils.class.getSimpleName();

    private static final AtomicReference<AMSUtils> sInstance=new AtomicReference<>();

    public static void systemReady(ClassLoader cl){
        sInstance.set(new AMSUtils(cl));
    }

    public static AMSUtils get(){
        return sInstance.get();
    }

    private final ClassLoader mCL;

    private AMSUtils(ClassLoader cl){
        mCL=cl;
    }

    public Class<?> getAMSClass() throws Exception {
        Class<?> amsClass = mCL.loadClass("com.android.server.am.ActivityManagerService");
        Log.d(TAG, "amsClass:" + amsClass);
        return amsClass;
    }

    public static final int FLAG_PERSISTENT = 1<<3;

    public int addPersistent(int flag){
        return BitUtils.addFlag(flag,FLAG_PERSISTENT);
    }

    public boolean hasPersistent(int flag){
        return BitUtils.hasFlag(flag,FLAG_PERSISTENT);
    }
}
